package com.abapi.pay.admin.service.impl;

import com.abapi.cloud.socket.pojo.TcpSession;
import com.abapi.pay.admin.service.AbstractEndpointService;
import com.abapi.pay.core.annotation.EndpointMapping;
import com.abapi.pay.core.biz.Encode;
import com.abapi.pay.core.constans.MessageType;
import com.abapi.pay.core.dto.AbstractBody;
import com.abapi.pay.core.dto.MessageDTO;
import io.netty.buffer.ByteBuf;
import org.springframework.stereotype.Service;

/**
 * @Author ldx
 * @Date 2019/11/1 15:24
 * @Description
 * @Version 1.0.0
 */
@Service
@EndpointMapping(value = MessageType.PING,desc = "客户端心跳")
public class PingServiceImpl implements AbstractEndpointService {
    @Override
    public void handler(TcpSession session, MessageDTO<AbstractBody> messageDTO) {
        MessageDTO result = new MessageDTO();
        result.setType(MessageType.PONG);
        ByteBuf resultBuf = session.alloc().buffer();
        resultBuf.writeBytes(Encode.encode(result));
        session.channel().writeAndFlush(resultBuf);
    }
}
